<?php

namespace PlatBundle\Controller;

use ApiBundle\Controller\BaseController;

class AccountController extends BaseController
{
    /*
     * 添加/编辑  超级管理员帐号
     */
    public function editAdminAccountAction($id)
    {
        if(!$this->get("session")->get("plat_id")){

            return $this->render('PlatBundle:Auth:login.html.twig');
        }
        $conn = $this->get("database_connection");


        $data['info'] = $conn->fetchAssoc("SELECT * FROM admin WHERE id = '". $id ."'");

        $district_name = $conn->fetchAssoc("SELECT name FROM district WHERE id = '". $data['info']['district_id'] ."'");

        $data['info']['district_name'] = $district_name['name'];

        if(empty($id)){
            $data['info'] = array("id"=>"0");
        }

        $data['district'] = $conn->fetchAll("SELECT * FROM district WHERE 1");



        return $this->render("PlatBundle:Account:editAccount.html.twig",array("data"=>$data));
    }

    /*
     * 管理员帐号列表
     */
    public function adminAccountListAction()
    {

        if(!$this->get("session")->get("plat_id")){

            return $this->render('PlatBundle:Auth:login.html.twig');
        }
        $data = $this->getApiData("ApiBundle:Public:getDistrict");
        return $this->render("PlatBundle:Account:index.html.twig",array("data"=>$data));
    }
}
